package com.cardone.platform.usercenter.controller;

import java.util.List;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.usercenter.dto.UsOrgTranslateDto;
import com.cardone.platform.usercenter.service.UsOrgTranslateService;

/**
 * 用户组织调动
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/usercenter/usOrgTranslate/")
@Controller
public class UsOrgTranslateController {
	/**
	 * 初始化数据绑定
	 *
	 * @param webDataBinder
	 *          数据绑定
	 */
	// @InitBinder
	// @Deprecated
	// public void initBinder(final WebDataBinder webDataBinder) {
	// }

	/**
	 * 用户组织调动：删除
	 *
	 * @param deleteUsOrgTranslate
	 *          用户组织调动对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
	public Callable<ReturnDataDto<String>> deleteJson(final UsOrgTranslateDto deleteUsOrgTranslate) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsOrgTranslateService.class).deleteByIds(deleteUsOrgTranslate);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsOrgTranslateController.log);
				}
			}
		};
	}

	/**
	 * 用户组织调动：分页查询
	 *
	 * @param findUsOrgTranslate
	 *          用户组织调动对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
	public void editHtml(final UsOrgTranslateDto findUsOrgTranslate, final Model model) {
		final UsOrgTranslateDto usOrgTranslate = ContextHolder.getBean(UsOrgTranslateService.class).findById(UsOrgTranslateDto.class, findUsOrgTranslate);

		model.addAttribute("usOrgTranslate", usOrgTranslate);
	}

	/**
	 * 用户组织调动：编辑
	 *
	 * @param findUsOrgTranslate
	 *          用户组织调动对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<UsOrgTranslateDto>> findByIdJson(final UsOrgTranslateDto findUsOrgTranslate, final Model model) {
		return new Callable<ReturnDataDto<UsOrgTranslateDto>>() {
			@Override
			public ReturnDataDto<UsOrgTranslateDto> call() throws Exception {
				try {
					final UsOrgTranslateDto usOrgTranslate = ContextHolder.getBean(UsOrgTranslateService.class).findById(UsOrgTranslateDto.class, findUsOrgTranslate);

					return ReturnDataUtils.newReturnData(usOrgTranslate);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsOrgTranslateController.log);
				}
			}
		};
	}

	/**
	 * 用户组织调动：查询
	 *
	 * @param findListUsOrgTranslate
	 *          用户组织调动对象
	 * @return 用户组织调动对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<List<UsOrgTranslateDto>>> findListByLikeCodeJson(final UsOrgTranslateDto findListUsOrgTranslate) {
		return new Callable<ReturnDataDto<List<UsOrgTranslateDto>>>() {
			@Override
			public ReturnDataDto<List<UsOrgTranslateDto>> call() throws Exception {
				try {
					final List<UsOrgTranslateDto> usOrgTranslateList = ContextHolder.getBean(UsOrgTranslateService.class).findListByLikeCode(UsOrgTranslateDto.class, findListUsOrgTranslate);

					return ReturnDataUtils.newReturnData(usOrgTranslateList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsOrgTranslateController.log);
				}
			}
		};
	}

	/**
	 * 用户组织调动：分页查询
	 *
	 * @param paginationUsOrgTranslate
	 *          用户组织调动对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<PaginationDto<UsOrgTranslateDto>>> paginationByLikeCodeJson(final UsOrgTranslateDto paginationUsOrgTranslate) {
		return new Callable<ReturnDataDto<PaginationDto<UsOrgTranslateDto>>>() {
			@Override
			public ReturnDataDto<PaginationDto<UsOrgTranslateDto>> call() throws Exception {
				try {
					final PaginationDto<UsOrgTranslateDto> usOrgTranslatePagination = ContextHolder.getBean(UsOrgTranslateService.class).paginationByLikeCode(UsOrgTranslateDto.class, paginationUsOrgTranslate);

					return ReturnDataUtils.newReturnData(usOrgTranslatePagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsOrgTranslateController.log);
				}
			}
		};
	}

	/**
	 * 用户组织调动：分页查询
	 *
	 * @param paginationUsOrgTranslate
	 *          用户组织调动对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
	public void paginationHtml(final UsOrgTranslateDto paginationUsOrgTranslate, final Model model) {
		final PaginationDto<UsOrgTranslateDto> usOrgTranslatePagination = ContextHolder.getBean(UsOrgTranslateService.class).paginationByLikeCode(UsOrgTranslateDto.class, paginationUsOrgTranslate);

		model.addAttribute("usOrgTranslatePagination", usOrgTranslatePagination);
	}

	/**
	 * 用户组织调动：保存
	 *
	 * @param saveUsOrgTranslate
	 *          用户组织调动对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
	public Callable<ReturnDataDto<String>> saveJson(final UsOrgTranslateDto saveUsOrgTranslate) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsOrgTranslateService.class).saveByIdOrCode(UsOrgTranslateDto.class, saveUsOrgTranslate);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsOrgTranslateController.log);
				}
			}
		};
	}
}
